﻿using DLUProject.Domain;
using DLUProject.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ColorLife.Core.Helper;
public partial class KTX_CTTinTuc : BaseUserControl
{
    public ModuleInstanceExtension moduleInstance { get; set; }
   
    public IServices<TinTuc> _serviceTinTuc { get; set; }
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public int IDTinTuc
    {
        get
        {
            if (Request.QueryString["IDTinTuc"] != null)
                return Request.QueryString["IDTinTuc"].ToInt();
            return -1;
        }
    }
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        if (!IsPostBack)
        {
            var tinTuc = _serviceTinTuc.Get(IDTinTuc);
            if (tinTuc == null)
            {
                Response.Redirect("Default.aspx");
            }
            Page.Title = tinTuc.TieuDe;

            lblTieuDe.Text = tinTuc.TieuDe;
            lblNoiDung.Text = tinTuc.NoiDung;
            lblNguoiThongBao.Text = tinTuc.TacGia;
            lblNgayDang.Text = tinTuc.NgayDang.ToShortDateString();

            

            List<ModuleInstance> modulesLeft = moduleInstance.GetByModulePosition(ModulePosition.Left);
            foreach (var item in modulesLeft)
            {
                BaseUserControl userControlX = (BaseUserControl)LoadControl(item.Module.Path);

                if (userControlX != null)
                {
                    userControlX.ModuleID = item.ModuleInstanceID.ToString();
                    userControlX.Title = item.Title;
                    userControlX.Params = item.Params;
                    userControlX.ShowHide = item.IsActive;
                    userControlX.State = item.State;
                    PlaceHolderRight.Controls.Add(userControlX);
                }
            }
            rptItems.DataSource = _serviceTinTuc.Table.OrderByDescending(c => c.IDTinTuc).Take(10);
            rptItems.DataBind();

            Repeater1.DataSource = _serviceTinTuc.Table.OrderByDescending(c => c.IDTinTuc).Take(20);
            Repeater1.DataBind();

           
        }
    }
}